using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using PersistenceObject.Framework.Expressions;

namespace PersistenceObject.Framework
{
    public class Delete : IDelete, ISqlAccess
    {
        public Delete() { }

        private IDataSession session;
        public IDataSession Session
        {
            get { return session; }
            set { session = value; }
        }

        private Table table;
        public Table Table
        {
            get { return table; }
            set { table = value; }
        }

        private Expression expressions;
        public Expression Expressions
        {
            get { return expressions; }
            set { expressions = value; }
        }

        public int Execute()
        {
            IDbCommand comm = CommandBuilder.Delete(this.Session.DbDriver, this.table.Name, this.expressions);
            DataSession.LastSql = comm.CommandText;
            return this.Session.ExecuteNonQuery(comm);
        }
    }
}